/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.fzhucc.modules.pms.controller;

import com.fzhucc.annotation.Log;
import com.fzhucc.annotation.rest.AnonymousGetMapping;
import com.fzhucc.annotation.rest.AnonymousPostMapping;
import com.fzhucc.modules.expert.domain.dto.ExpertAddDto;
import com.fzhucc.modules.expert.domain.dto.ExpertCountQueryCriteria;
import com.fzhucc.modules.expert.domain.dto.ExpertEditDto;
import com.fzhucc.modules.expert.domain.dto.ExpertQueryCriteria;
import com.fzhucc.modules.expert.service.ExpertService;
import com.fzhucc.modules.pms.domain.dto.ProjectExpertScoreDto;
import com.fzhucc.modules.pms.domain.dto.ProjectRandomManTypeDto;
import com.fzhucc.modules.pms.domain.dto.ProjectScoreDistributionDto;
import com.fzhucc.modules.pms.service.ProjectScoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yyg
 * @date 2022-11-15
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "项目库评分:管理")
@RequestMapping("/api/projectScore")
public class ProjectScoreController {

    private final ProjectScoreService projectScoreService;

    @Log("通过项目查询专家列表")
    @ApiOperation("通过项目查询专家列表")
    @GetMapping("/getExpertByProjectId")
    @PreAuthorize("@el.check('projectScore:list')")
    public ResponseEntity<Object> getExpertByProjectId(String projectId){
        return new ResponseEntity<>(projectScoreService.getExpertByProjectId(projectId), HttpStatus.OK);
    }


    @Log("根据条件随机赛选专家、智库List")
    @ApiOperation("根据条件随机赛选专家、智库List")
    @PostMapping("/randomManList")
    @PreAuthorize("@el.check('projectScore:list')")
    public ResponseEntity<Object> randomManList(@RequestBody ProjectRandomManTypeDto projectRandomManTypeDto){
        return new ResponseEntity<>(projectScoreService.randomManList(projectRandomManTypeDto),HttpStatus.OK);
    }

    @Log("项目评分表分配专家")
    @ApiOperation("项目评分表分配专家")
    @PostMapping("/distribution")
    @PreAuthorize("@el.check('projectScore:list')")
    public ResponseEntity<Object> distribution(@RequestBody ProjectScoreDistributionDto projectScoreDistributionDto){
        projectScoreService.dodistribution(projectScoreDistributionDto);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @Log("查询已分配自己的项目")
    @ApiOperation("查询已分配自己的项目")
    @GetMapping("/getProjectByLoginUser")
    public ResponseEntity<Object> getProjectByLoginUser(Pageable pageable){
        return new ResponseEntity<>(projectScoreService.getProjectByLoginUser(pageable), HttpStatus.OK);
    }


    @Log("专家评分")
    @ApiOperation("专家评分")
    @PostMapping("/expertRating")
    @PreAuthorize("@el.check('projectScore:list')")
    public ResponseEntity<Object> expertRating(@RequestBody ProjectExpertScoreDto projectExpertScoreDto){
        projectScoreService.expertRating(projectExpertScoreDto);
        return new ResponseEntity<>(HttpStatus.OK);
    }


    @Log("查询单个项目的专家评分情况")
    @ApiOperation("查询单个项目的专家评分情况")
    @GetMapping("/getProjectScoreByProjectId")
    @PreAuthorize("@el.check('projectScore:list')")
    public ResponseEntity<Object> getProjectScoreByProjectId(String projectId){
        return new ResponseEntity<>(projectScoreService.getProjectScoreByProjectId(projectId),HttpStatus.OK);
    }

    @Log("查询单个项目的专家评分情况 区分项目等级阶段")
    @ApiOperation("查询单个项目的专家评分情况 区分项目等级阶段")
    @GetMapping("/getProjectScoreByProjectIdSiftLevel")
    @PreAuthorize("@el.check('projectScore:list')")
    public ResponseEntity<Object> getProjectScoreByProjectIdSiftLevel(String projectId){
        return new ResponseEntity<>(projectScoreService.getProjectScoreByProjectIdSiftLevel(projectId),HttpStatus.OK);
    }


    @Log("查询单个项目是否评分")
    @ApiOperation("查询单个项目是否评分")
    @GetMapping("/getIsScoreByProjectId")
    @PreAuthorize("@el.check('projectScore:list')")
    public ResponseEntity<Object> getIsScoreByProjectId(String projectId){
        return new ResponseEntity<>(projectScoreService.getIsScoreByProjectId(projectId),HttpStatus.OK);
    }


    @Log("查询单个项目的登录用户专家评分情况  包含所有的项目等级阶段评分")
    @ApiOperation("查询单个项目的登录用户专家评分情况  包含所有的项目等级阶段评分")
    @GetMapping("/getByProjectIdAndLoginUser")
    @PreAuthorize("@el.check('projectScore:list')")
    public ResponseEntity<Object> getByProjectIdAndLoginUser(String projectId){
        return new ResponseEntity<>(projectScoreService.getByProjectIdAndLoginUser(projectId),HttpStatus.OK);
    }

    @Log("查询单个项目的登录用户专家评分情况  区分项目等级阶段评分")
    @ApiOperation("查询单个项目的登录用户专家评分情况  区分项目等级阶段评分")
    @GetMapping("/getByProjectIdAndLoginUserSiftLevel")
    @PreAuthorize("@el.check('projectScore:list')")
    public ResponseEntity<Object> getByProjectIdAndLoginUserSiftLevel(String projectId){
        return new ResponseEntity<>(projectScoreService.getByProjectIdAndLoginUserSiftLevel(projectId),HttpStatus.OK);
    }

}